# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Co-Maintainer: Andreas 'Segaja' Schleifer <segaja at archlinux dot org>
# Contributor: Carsten Feuls <archlinux@carstenfeuls.de>

_gemname=eventmachine
pkgname=ruby-${_gemname}
pkgver=1.2.7
pkgrel=6
pkgdesc='EventMachine: fast, simple event-processing library'
url='http://rubyeventmachine.com'
arch=('loong64' 'x86_64')
license=('Ruby' 'GPL2')
depends=('ruby' 'ruby-rdoc' 'openssl')
options=('!emptydirs')
source=(${pkgname}-${pkgver}.tar.gz::https://github.com/eventmachine/eventmachine/archive/v${pkgver}.tar.gz)
sha256sums=('32692ae79bed595445d889ab83d862200a18964c395e48cfab01ba6e9ff6437c')
sha512sums=('768ec084903dce4c737cf564fce7886a3e7e5b7d4a89c2baea3e998130c53dc00488eaa2d8e9b0133d9e4d8fffbde80c3025403881486a7968c2d84425cc1f50')

prepare() {
  cd ${_gemname}-${pkgver}
  sed 's|git ls-files README.md CHANGELOG.md GNU LICENSE|find|' -i ${_gemname}.gemspec
  sed 's|git ls-files|find|' -i ${_gemname}.gemspec
}

build() {
  cd ${_gemname}-${pkgver}
  gem build ${_gemname}.gemspec
}

package() {
  cd ${_gemname}-${pkgver}
  local _gemdir="$(ruby -e'puts Gem.default_dir')"
  gem install --ignore-dependencies --no-user-install -i "${pkgdir}/${_gemdir}" -n "${pkgdir}/usr/bin" ${_gemname}*.gem
  install -Dm 644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
  install -Dm 644 README.md -t "${pkgdir}/usr/share/doc/${pkgname}"
  rm "${pkgdir}/${_gemdir}/cache/${_gemname}-${pkgver}.gem" \
      "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/ext/fastfilereader/Makefile" \
      "${pkgdir}/${_gemdir}/gems/${_gemname}-${pkgver}/ext/Makefile"
  rm -rf "${pkgdir}/${_gemdir}/doc/${_gemname}-${pkgver}/ri/ext/"
  find "${pkgdir}/${_gemdir}" \( -name 'mkmf.log' -or -name 'gem_make.out' \) -delete
}
